function register() {
	var account = $('#r_account').val();
	var rCode = $('#r_code').val();
	var newPassword = $('#r_newPassword').val();
	var surePassword = $('#r_surePassword').val();

	var code = dataGet("code");

	if(account.length <5 || account.length > 15 ) {
		alert("用户名请输入5-15位字符");
		return;
	}

	if(rCode.length != 4) {
		alert("验证码为4位，请确定");
		return;
	}

	if(newPassword.length <6 || newPassword.length > 20 ) {
		alert("密码（6-20个字符，数字或密码组成）");
		return;
	}

	if(newPassword!=surePassword) {
		alert("两次输入密码不一致");
		return;
	}

	if(surePassword.length <6 || surePassword.length > 20 ) {
		alert("请确认密码（6-20个字符，数字或密码组成）");
		return;
	}

	var data = "&crusrMobile="+account+"&crusrPassword="+newPassword+"&crusrType="+1+"&code="+rCode+"&crusrPoints="+0 + "&openCode=" + code;
	var url = urlfile + "coreUser/register";
	ajaxTool("post",data,url,
		function error(XMLHttpRequest, textStatus, errorThrown,fnErr){
			alert("error:" + data);
		},
		function success(data){
			if(!data.success) {
				alert(data.errMsg);
			}else{
				dataSave("openId", "");
				nextView("../../../page/OAuthGetCodeLogin.html");
			}
		}
	);
}

function cheakAccount() {
	var account = $('#r_account').val();

	var checkFlag = Validator.stringIsMobileNo(account);
	if(!checkFlag) {
		alert("请检查手机号是否正确");
		return;
	}

	var data = "&crusrName="+account;
	var url = urlfile + "coreUser/valid/name";
	ajaxTool("post",data,url,
		function error(XMLHttpRequest, textStatus, errorThrown,fnErr){
			alert("error:" + XMLHttpRequest);
		},
		function success(data){
			if(!data.success) {
				alert(data.errMsg);
			}
		}
	);
}

function sendCode(type) {//1:注册， 2：忘记密码
	var account = $('#r_account').val();
	var checkFlag = Validator.stringIsMobileNo(account);
	if(!checkFlag) {
		alert("请检查手机号是否正确");
		return;
	}

	$('#sendCode').removeAttr("onclick");
	settime(60,type);
	
	/****************************发送验证码*******************************/
	var data = "&crusrMobile="+account; 
	var url = "";

	if(type==1) {
		url = urlfile + "coreUser/register/send";
	} else {
		url = urlfile + "coreUser/forget/send";
	}

	ajaxTool("post",data,url,
		function error(XMLHttpRequest, textStatus, errorThrown,fnErr){
			alert("error:" + XMLHttpRequest);
		},
		function success(data){
			alert(data.errMsg);
		}
	);
}
//验证码倒计时
var mytime;
function settime(time,type) {
	var sendCode = $('#sendCode');
	if (time == 0) { 
		sendCode.html("获取验证码"); 
		clearTimeout(mytime);
		sendCode.attr('onclick', 'sendCode('+type+')');   
		return;
	} else { 
		var valString = "重新发送(" + time + ")";
		sendCode.html(valString);     
		time--; 
	} 

	mytime = setTimeout(function() { 
		settime(time,type); 
	},1000);
}

function login() {
	var code = GetParpam("code");
	dataSave("code",code);

	var account = $('#l_account').val();
	var password = $('#l_password').val();
	var code = dataGet("code");
	var loginType = dataGet("loginType");

	if(account.length <5 || account.length > 15 ) {
		alert("用户名请输入5-15位字符");
		return;
	}

	if(password.length <6 || password.length > 20 ) {
		alert("密码（6-20个字符，数字或密码组成）");
		return;
	}

	var data = "&crusrMobile="+account + "&crusrPassword="+password; 
	if(dataGet("openId") == "") {
		dataSave("openId", "");
		data += "&code=" + code;
	}

	var url = urlfile + "coreUser/login";

	ajaxTool("post",data,url,
		function error(XMLHttpRequest, textStatus, errorThrown,fnErr){
			alert("error:" + XMLHttpRequest);
		},
		function success(data){
			if(!data.success) {
				alert(data.errMsg);
			}else{
				dataSave("userUuid", data.data.crusrUuid);
				dataSave("userName", data.data.crusrName);

				dataSave("openId", data.data.crusrOpenid);

				dataSave("userPhone", data.data.crusrMobile);
				dataSave("userPoints", data.data.crusrPoints);
				dataSave("userBalance", data.data.crusrBalance);
				dataSave("userSex", data.data.crusrGender);

				dataSave("userAddress", data.data.crusrAddress);
				dataSave("userBirthday", data.data.crusrBirthday);  

				dataSave("isLogined",true);

				var now = (new Date()).Format("yyyy/MM/dd hh:mm:ss");
				dataSave("nowTime", now);
				
				if(loginType == "personIndex"){
					nextView("../person/personIndex.html");
					return;
				}

				if( loginType == "kuaidi"){
					nextView("../bargain/goBargainKD.html");
					return;
				}

				if( loginType == "huishou"){
					nextView("../bargain/goBargainHS.html");
					return;
				}
				
				if( loginType == "addlively"){
					nextView("../addLively/addLivelyIndex.html");
					return;
				}

				if( loginType == "equipment"){
					nextView("../equipment/equipment.html");
					return;
				}
				
				if( loginType == "favorable_home"){
					nextView("../store/favorable_home.html");
					return;
				}
				
				backPage();
	
			}
		}
	);

}


function forgetPassword() {
	var account = $('#r_account').val();

	var rCode = $('#r_code').val();

	var newPassword = $('#n_password').val();

	if(account.length <5 || account.length > 15 ) {
		alert("用户名请输入5-15位字符");
		return;
	}

	if(rCode.length != 4) {
		alert("验证码为4位，请确定");
		return;
	}

	if(newPassword.length <6 || newPassword.length > 20 ) {
		alert("密码（6-20个字符，数字或密码组成）");
		return;
	}

	var data = "&crusrMobile="+account+"&crusrPassword="+newPassword+"&code="+rCode;
	var url = urlfile + "coreUser/forget";
	ajaxTool("post",data,url,
		function error(XMLHttpRequest, textStatus, errorThrown,fnErr){
			alert("error:" + data);
		},
		function success(data){
			if(!data.success) {
				alert(data.errMsg);
			}else{
				nextView("../../../page/OAuthGetCodeLogin.html");
			}
		}
	);
}

function toRegister() {
	var code = GetParpam("code");
	dataSave("code",code);
	nextView("../../../page/OAuthGetCodeRegister.html");
}